package cn.hnu.jpa.jpaExample.OneWayAssociation;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

@Entity 
public class Person implements Serializable{
	/**
	 * 单向关联  person and address
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private Address addr;
	private String name;
	@Id @GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	@OneToOne(cascade = {CascadeType.ALL},fetch = FetchType.LAZY) //延迟加载
	@JoinColumn(name = "addr_id")
	//若不想使用address的主键作为外键 可以采用referencedColumnName="ref_id"
	//@JoinColumn(name = "addr_id",referencedColumnName = "ref_id") 这样在
	//address表中会添加ref_id列 作为引用列
	public Address getAddr() {
		return addr;
	}
	
	public void setAddr(Address addr) {
		this.addr = addr;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}
